<template>
  <div class="container">
    <div class="view-header">
      <el-card class="view-card">
        <div class="filter-header">
          <el-form :inline="true" :model="filter" label-position="left" class="demo-form-inline">
            <el-row :gutter="20">
              <el-col :span="5">
                <div class="grid-content bg-purple">
                  <el-form-item label="文章标题" size="small">
                    <el-input v-model="filter.title" placeholder="请输入内容" />
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple">
                  <el-form-item label="类型" size="small">
                    <el-input v-model="filter.type" placeholder="请输入内容" />
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple">
                  <el-form-item label="文章编号" size="small">
                    <el-input v-model="filter.articleCode" placeholder="请输入内容" />
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple">
                  <el-form-item label="是否开放" size="small">
                    <el-select v-model="filter.hideStatus" placeholder="请选择">
                      <el-option label="隐藏" :value="0" />
                      <el-option label="开放" :value="1" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple">
                  <el-form-item label="是否草稿" size="small">
                    <el-select v-model="filter.draftStatus" placeholder="请选择">
                      <el-option label="草稿" :value="0" />
                      <el-option label="非草稿" :value="1" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple">
                  <el-form-item label="创建人" size="small">
                    <el-select
                      v-model="filter.userId"
                      filterable
                      remote
                      clearable
                      no-match-text="无匹配数据"
                      no-data-text="无匹配数据"
                      placeholder="请输入创建人姓名"
                      :remote-method="remoteSearchUser"
                    >
                      <el-option
                        v-for="item in user"
                        :key="item.id"
                        :label="item.realName"
                        :value="item.id"
                      />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-form-item label="创建时间" size="small">
                    <el-date-picker
                      v-model="dateList"
                      type="datetimerange"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      @change="changeDataFormat"
                    />
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple">
                  <el-form-item size="small">
                    <el-button type="primary" @click="fetch">查询</el-button>
                    <el-button type="primary" @click="fetch">重置</el-button>
                    <el-button type="primary" @click="fetch">导出</el-button>
                  </el-form-item>
                </div>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <div>
          <el-button type="text" size="small" style="width:100%" class="blt-btn" @click="save">+ 添加</el-button>
        </div>
        <el-table
          :data="items"
          style="width: 100%;margin-bottom: 20px;"
          row-key="id"
          :default-expand-all="false"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        >
          <el-table-column
            prop="articleCode"
            label="文章编号"
            sortable
            align="center"
            min-width="10%"
          />
          <el-table-column
            prop="type"
            label="所属类型"
            sortable
            align="center"
            min-width="10%"
          />
          <el-table-column
            prop="title"
            label="标题"
            sortable
            align="center"
            min-width="10%"
          />
          <el-table-column
            prop="remarks"
            label="注释"
            sortable
            align="center"
            min-width="10%"
          />
          <el-table-column
            prop="avgScore"
            label="均分"
            sortable
            align="center"
            min-width="10%"
          />
          <el-table-column
            fixed="right"
            label="是否开放"
            align="center"
            min-width="10%"
          >
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.hideStatus"
                disabled
              />
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="是否草稿文件"
            align="center"
            min-width="10%"
          >
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.draftStatus"
                disabled
              />
            </template>
          </el-table-column>
          <el-table-column
            prop="createName"
            label="创建人"
            align="center"
            sortable
            min-width="10%"
          />
          <el-table-column
            prop="createDate"
            label="创建日期"
            sortable
            align="center"
            min-width="10%"
          />
          <el-table-column
            fixed="right"
            label="操作"
            align="center"
            min-width="20%"
          >
            <template slot-scope="scope">
              <el-button v-if="scope.row.level !== '3'" type="text" size="small">追加</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          layout="prev, pager, next"
          :page-size="pagination.size"
          :current-page="pagination.current"
          :total="pagination.total"
          @current-change="fetch"
        />
      </el-card>
    </div>
  </div>
</template>

<script>

import { queryUserInfo } from '@/api/user'

export default {
  data() {
    return {
      user: [],
      dateList: [],
      items: [],
      filter: {
      },
      pagination: {
        current: 1,
        size: 10,
        total: 0
      }
    }
  },
  created() {
  },
  methods: {
    // 日期格式转换
    changeDataFormat(value) {
      this.filter.startTime = value ? `${value[0]} 00:00:00` : ''
      this.filter.endTime = value ? `${value[1]} 23:59:59` : ''
    },
    // 远程搜索姓名展示人员下拉框
    async remoteSearchUser(name) {
      console.log('remoteSearchUser =>' + name)
      const params = { name }
      const res = await queryUserInfo(params)
      this.user = res.data
    },
    async fetch() {
    },
    // 添加按钮跳转添加页面
    save() {
      this.$router.push({ path: '/article/id?type=add' })
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  font-size: 30px;
  min-height: calc(96vh);
  background: #f2f3f7;
  position: relative;
}
.filter{
  &-header{
    width: 100%;
  }
  &-input {
    width:5vh
  }
}
.view{
  &-header{
  }
  &-card{
    margin: 1px 1vh 0 1vh;
  }
}
.blt {
  &-btn {
    width: 100%;
    border-style:dashed;
    border-color: #d9d9d9;
    border-width: 1px
  }
}
::v-deep .el-input__inner{
  margin-right: 5vh;
}
</style>
